/*
 * @(#)SetupOptionFactory.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.setup;

import java.util.Hashtable;

/**
 *  Defines setup option for System Setup - Options Setup
 *
 *  @author           Kennedy Lam
 *  @company          DCIVision Limited
 *  @creation date    28/07/2003
 *  @version          $Revision: 1.8 $
 */
public class SetupOptionFactory {

  public static final String REVISION = "$Revision: 1.8 $";


  private static final Hashtable hOptions;
  private static final SetupOptionItem[] ITEM;
  private static final int DEFAULT_INDEX;

  // initialize the factory
  static {
    ITEM = new SetupOptionItem[] {
      new SetupOptionItem(1, "SetupOptionCountry",
        "setupOption.columnheader.option_country_list",
        "com.dcivision.setup.dao.SetupOptionCountryDAObject"),

//      new SetupOptionItem(2, "SetupOptionIndustry",
//        "setupOption.columnheader.option_industry_list",    
//        "com.dcivision.setup.dao.SetupOptionIndustryDAObject"),
//
//      new SetupOptionItem(3, "SetupOptionSalutation",
//        "setupOption.columnheader.option_salutation_list",
//        "com.dcivision.setup.dao.SetupOptionSalutationDAObject"), 
//        
//      new SetupOptionItem(4, "SetupOptionWorkflowCategory",
//        "setupOption.columnheader.option_workflow_category_list",
//        "com.dcivision.setup.dao.SetupOptionWorkflowCategoryDAObject"),
//        
//      new SetupOptionItem(4, "SetupOptionFormCategory",
//        "setupOption.columnheader.option_form_category_list",
//        "com.dcivision.setup.dao.SetupOptionFormCategoryDAObject"),
        
      new SetupOptionItem(2, "SetupOptionDocumentRelationship",
        "setupOption.columnheader.option_document_relationship_list",
        "com.dcivision.setup.dao.SetupOptionDocumentRelationshipDAObject")
    };
    DEFAULT_INDEX = 0; // set default item, must match the ListOptionsSetup.jsp setting

    hOptions = new Hashtable(); // for searching purpose
    hOptions.put("SetupOptionCountry", ITEM[0]);
//    hOptions.put("SetupOptionIndustry", ITEM[1]);
//    hOptions.put("SetupOptionSalutation", ITEM[2]);
//   hOptions.put("SetupOptionWorkflowCategory", ITEM[3]);
//    hOptions.put("SetupOptionFormCategory", ITEM[3]);
    hOptions.put("SetupOptionDocumentRelationship", ITEM[1]);
  }

  public static boolean isRegistered(String optName) {
    return hOptions.containsKey(optName);
  }

  public static SetupOptionItem getSetupOptionItem(String optName) {
    return (SetupOptionItem) hOptions.get(optName);
  }

  public static SetupOptionItem[] getItemsInOrder() {
    return ITEM;
  }

  /**
   *  retrieve DAO name from given option name
   *  @param optName Setup Option Name
   *  @return full qualified DAO class name
   */
  public static String getDAObjectName(String optName) {
    if ( optName == null || !isRegistered(optName) )
      return ITEM[DEFAULT_INDEX].getDAObjectName();

    return ((SetupOptionItem)hOptions.get(optName)).getDAObjectName();
  }
}
